<?php

namespace addons\config\model;

/**
 * 系统消息表
 * Class SystemMessage
 * @package addons\config\model
 */
class SystemMessage extends \web\common\model\BaseModel{
    
    protected function _initialize(){
        $this->tableName = 'system_message';
    }

    public function message_add($user_id,$title,$content,$type = 0)
    {
        $data['title'] = $title;
        $data['content'] = $content;
        $data['user_id'] = $user_id;
        $data['type'] = $type;
        $data['create_time'] = NOW_DATETIME;
        return $this->add($data);
    }

    /**
     * 关联分类表列表
     * @param int $pageIndex
     * @param int $pageSize
     * @param string $filter
     * @param string $fields
     * @param string $order
     * @return mixed
     */
    public function getMessageList($pageIndex = -1, $pageSize = -1, $filter = '', $fields = '*', $order = 'a.id asc') {
        $sql = 'select '.$fields.' from ' . $this->getTableName() .' as a left join tp_member_account as b on b.id=a.user_id ';
        if (!empty($filter))
            $sql .= ' where ' . $filter;
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }
}
